<%@page import="com.iflysse.bbs.dao.impl.UserDaoImpl"%>
<%@page import="com.iflysse.bbs.dao.UserDao"%>
<%@page import="com.iflysse.bbs.model.UserInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../base.jsp"%>

<%
	//检查是否登陆
	if( session.getAttribute("currentUser") == null){
		request.getRequestDispatcher("/index_handler.jsp").forward(request, response);
		return;
	}

	String oldPwd = request.getParameter("oldPwd") == null ? null
			: request.getParameter("oldPwd").toString().trim();
	String newPwd = request.getParameter("newPwd") == null ? null
			: request.getParameter("newPwd").toString().trim();

	String confirmPwd = request.getParameter("confirmPwd") == null ? null
			: request.getParameter("confirmPwd").toString().trim();
	
	UserInfo currentUser = (UserInfo) session.getAttribute("currentUser");
	
	UserDao userDao = new UserDaoImpl();
	
	UserInfo user = userDao.getUser(currentUser.getId());
	if(!user.getPassword().equals(oldPwd)){
		request.setAttribute("msg", "旧密码不正确，请确认");
		request.getRequestDispatcher("/pages/personal/editPwd.jsp").forward(request, response);
		return;
	}else{
		userDao.updatePwd(currentUser.getId(), newPwd);
		request.setAttribute("msg", "恭喜，密码修改成功");
		request.getRequestDispatcher("/pages/personal/editPwd.jsp").forward(request, response);
	
	}
	
%>